package com.dynamic.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.dynamic.entity.UserInfo;
import com.dynamic.repository.UserInfoRepository;
import com.dynamic.service.UserInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author Lance
 * @version 1.0.0
 * @data 2022-10-28 14:02
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserInfoServiceImpl implements UserInfoService {

    private final UserInfoRepository userInfoRepository;

    @DS("master")
    @Override
    public UserInfo findMasterUserInfo(String id) {
        Optional<UserInfo> repository = userInfoRepository.findById(id);
        return repository.get();
    }
    @DS("master")
    @Override
    public List<UserInfo> findMasterUserInfoList() {

        return userInfoRepository.findAll();
    }

    @DS("slave_1")
    @Override
    public UserInfo findSlaveUserInfo(String id) {
        UserInfo repository = userInfoRepository.getOne(id);
        return repository;
    }

    @DS("slave_1")
    @Override
    public List<UserInfo> findSlaveUserInfoList() {
        return userInfoRepository.findAll();
    }
}
